package diff.tests;

import java.util.List;
import java.util.ArrayList;
import diff.*;

/**
 * Diff test program. This is NOT a unit test suite, though it will become one.
 *
 * @author Arseny Kapoulkine
 */
public class TestProgram
{
    /**
     * Default entry point
     *
     * @param args - command line arguments
     */
    public static void main(String[] args)
    {
        List source_text = new ArrayList();
        source_text.add("#include <stdio.h>");
        source_text.add("");
        source_text.add("int main(int argc, char** argv)");
        source_text.add("{");
        source_text.add("    printf(\"Hello, world!\");");
        source_text.add("}");

        Text source = new Text(source_text);

        Diff diff = new Diff();

        {
            DiffPacket packet = new DiffPacket(0, 1, new ArrayList());
            packet.contents.add("#include <cstdio>");

            diff.getPackets().add(packet);
        }

        {
            DiffPacket packet = new DiffPacket(1, 2, null);

            diff.getPackets().add(packet);
        }

        {
            DiffPacket packet = new DiffPacket(5, 5, new ArrayList());
            packet.contents.add("    return 0");

            diff.getPackets().add(packet);
        }

        System.out.println("Source text:");
        source.debugPrint();

        System.out.println("Patched text:");
        (new Text(diff.apply(source.getContents()))).debugPrint();

        List source2_text = new ArrayList();
        source2_text.add("#include <iostream>");
        source2_text.add("int main(int argc, char** argv)");
        source2_text.add("{");
        source2_text.add("    using namespace std;");
        source2_text.add("    cout << \"Hello, world!\" << endl;");
        source2_text.add("}");


        Text source2 = new Text(source2_text);

        System.out.println("Source text:");
        source.debugPrint();

        System.out.println("Second source text:");
        source2.debugPrint();

        // reuse diff
        diff = Diff.calculate(source.getContents(), source2.getContents());

        diff.debugPrint();

        System.out.println("Patched text:");
        (new Text(diff.apply(source.getContents()))).debugPrint();

        // now try two files
        {
            Text t1 = new Text("TestData/diff/test_0_file_1.txt");
            Text t2 = new Text("TestData/diff/test_0_file_2.txt");

            System.out.println("Source file text:");
            t1.debugPrint();

            System.out.println("Second source file text:");
            t2.debugPrint();

            diff = Diff.calculate(t1.getContents(), t2.getContents());

            diff.debugPrint();

            System.out.println("Patched text:");
            (new Text(diff.apply(t1.getContents()))).debugPrint();
        }
    }
}
